
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>浏览页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
    </head>
    <body class="pear-container">
    
        <!-- 顶部查询表单 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form top-search-from">
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">ID</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="text" autocomplete="off" name="novel_sn" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="hidden" autocomplete="off" name="title[]" value="like" class="layui-input inline-block">
                                <input type="text" autocomplete="off" name="title[]" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商家</label>
                        <div class="layui-input-block">
                            <div name="business_id" id="business_id" value="" ></div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">上线时间</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block" id="start_time">
                                <input type="text" autocomplete="off" name="start_time[]" id="start_time-date-start" class="layui-input inline-block" placeholder="开始时间">
                                -
                                <input type="text" autocomplete="off" name="start_time[]" id="start_time-date-end" class="layui-input inline-block" placeholder="结束时间">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">同步时间</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block" id="created_at">
                                <input type="text" autocomplete="off" name="created_at[]" id="created_at-date-start" class="layui-input inline-block" placeholder="开始时间">
                                -
                                <input type="text" autocomplete="off" name="created_at[]" id="created_at-date-end" class="layui-input inline-block" placeholder="结束时间">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label"></label>
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
                            <i class="layui-icon layui-icon-search"></i>查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md" lay-submit lay-filter="table-reset">
                            <i class="layui-icon layui-icon-refresh"></i>重置
                        </button>
                    </div>
                    <div class="toggle-btn">
                        <a class="layui-hide">展开<i class="layui-icon layui-icon-down"></i></a>
                        <a class="layui-hide">收起<i class="layui-icon layui-icon-up"></i></a>
                    </div>
                </form>
            </div>
        </div>
        
        <!-- 数据表格 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="data-table" lay-filter="data-table"></table>
            </div>
        </div>

        <!-- 表格顶部工具栏 -->
        <script type="text/html" id="table-toolbar">
            <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="batchSelect">
                <i class="layui-icon"></i>选择
            </button>
        </script>


        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script src="/app/admin/admin/js/common.js"></script>
        <script src="/app/admin/admin/js/functions.js"></script>
        <script src="/app/admin/admin/js/md5.js"></script>
        
        <script>
            let callback = layui.url().search['callback']??'';

            // 相关常量
            const PRIMARY_KEY = "id";
            const SELECT_API = "/app/admin/novel/index/select?status=1&task_status=2";

            let where = {"status":"1","task_status":"2"};
            let isHide =false;

            // 字段 添加时间 created_at
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#created_at",
                    range: ["#created_at-date-start", "#created_at-date-end"],
                    type: "datetime",
                    mark: date_today_mark,
                });
            })

            // 字段 添加时间 created_at
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#start_time",
                    range: ["#start_time-date-start", "#start_time-date-end"],
                    type: "datetime",
                    mark: date_today_mark,
                });
            })

            // 字段 商家 business_id
            layui.use(["jquery", "xmSelect", "popup"], function() {
                layui.$.ajax({
                    url: "/app/admin/novel/business/select?format=select&limit=1000",
                    dataType: "json",
                    async:true,
                    headers: get_header({"format":"select"}),
                    success: function (res) {
                        layui.xmSelect.render({
                            el: "#business_id",
                            name: "business_id",
                            filterable: true,
                            data: res.data,
                            model: {"icon":"hidden","label":{"type":"text"}},
                            clickClose: true,
                            radio: true,
                        })
                        if (res.code) {
                            layui.popup.failure(res.msg);
                        }
                    }
                });
            });

            // 表格渲染
            layui.use(["table", "form", "common", "popup", "util", 'tab', ], function() {
                let table = layui.table;
                let form = layui.form;
                let $ = layui.$;
                let common = layui.common;
                let util = layui.util;
                
				// 表头参数
				let cols = [
					{
						type: "checkbox", align: "center"
					},{
						title: "ID",align: "center", field: "novel_sn",minWidth:100,sort:true,
					},{
						title: "标题",align: "center", field: "title",minWidth:150,
					},{
						title: "封面图",align: "center", field: "main_image",minWidth:100, templet: function (d) {
							return '<img src="'+encodeURI(d['main_image'])+'" style="max-width:32px;max-height:32px;" alt="" />'
						}
					},{
						title: "商家",align: "center", field: "business_name",minWidth:100,
					}
                    , {field: 'plan_nums', title: '方案数量',width:100,sort:true}
                    , {field: 'really_income', title: '真实收益',width:120,sort:true}
                    , {field: 'really_spread_num', title: '真实推广人数',width:150,sort:true}
                    , {field: 'start_time', title: '上线时间',width:160,sort:true}
                    , {field: 'created_at', title: '同步时间',width:160,sort:true}
                    , {field: 'labels', title: '标签',width:180}
				];
				
				// 渲染表格
				table.render({
				    elem: "#data-table",
				    url: SELECT_API,
				    page: true,
                    headers: get_header(where),
				    cols: [cols],
				    skin: "line",
				    size: "lg",
				    toolbar: "#table-toolbar",
				    autoSort: false,
				    defaultToolbar: [{
				        title: "刷新",
				        layEvent: "refresh",
				        icon: "layui-icon-refresh",
				    }, "filter", "print", "exports"],
				    done: function () {
				        layer.photos({photos: 'div[lay-id="data-table"]', anim: 5});
				    }
				});
				
				// 获取表格中下拉或树形组件数据
				let apiResults = {};
				apiResults["position"] = [];

                // 表格顶部工具栏事件
                table.on("toolbar(data-table)", function(obj) {
                    if (obj.event === "refresh") {
                        refreshTable();
                    } else if (obj.event === "batchSelect") {
                        batchSelect(obj);
                    }
                });

                // 表格顶部搜索事件
                form.on("submit(table-query)", function(data) {
                    where = searchWhere(data.field);
                    table.reload("data-table", {
                        page: {
                            curr: 1
                        },
                        where: where,
                        headers: get_header(where)
                    })
                    return false;
                });
                
                // 表格顶部搜索重置事件
                form.on("submit(table-reset)", function(data) {
                    where = {};
                    table.reload("data-table", {
                        where: where,
                        headers: get_header(where)
                    })
                });
                
                // 字段允许为空
                form.verify({
                    phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
                    email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
                    url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
                    number: [/(^$)|^\d+$/,'只能填写数字'],
                    date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
                    identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
                });

                // 表格排序事件
                table.on("sort(data-table)", function(obj){
                    where.field=obj.field;
                    where.order=obj.type;
                    table.reload("data-table", {
                        initSort: obj,
                        scrollPos: "fixed",
                        where: where,
                        headers: get_header(where)
                    });
                });


                // 删除多行
                let batchSelect = function(obj) {
                    // let checkIds = common.checkField(obj, PRIMARY_KEY);
                    // if (checkIds === "") {
                    //     layui.popup.warning("未选中数据");
                    //     return false;
                    // }
                    var checkData = table.checkStatus('data-table');
                    if(checkData.data.length==0){
                        layer.confirm('还没勾选,确定要退出吗?', function (index) {
                            layer.close(index);
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });

                        return false;
                    }

                    var data=[];
                    $.each(checkData.data,function (i,v) {
                        data.push(v);
                    })
                    if(callback=='search_manage_list'){
                        parent.search_manage_list(data);
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    }
                }

                // 刷新表格数据
                window.refreshTable = function(param) {
                    table.reloadData("data-table", {
                        scrollPos: "fixed"
                    });
                }
            })

        </script>
    </body>
</html>
